
/** 
*Copyright 2017 Yonyou Corporation Ltd. All Rights Reserved.
* This software is published under the terms of the Yonyou Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : dmscloud.manage
*
* @File name : PermissionMenuRangeServiceImpl.java
*
* @Author : yll
*
* @Date : 2017年4月5日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年4月5日    yll    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.cyxdms.sysAuth.service.service.permission;

import com.yonyou.cyx.function.exception.ServiceBizException;
import com.yonyou.cyx.function.utils.common.StringUtils;
import com.yonyou.cyxdms.sysAuth.service.constants.ManageDictCodeConstants;
import com.yonyou.cyxdms.sysAuth.service.constants.StringUtil;
import com.yonyou.cyxdms.sysAuth.service.mapper.PermissionMenuRangeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
* 菜单数据范围权限实现类
* @author yll
* @date 2017年4月5日
*/
@Service
public class PermissionMenuRangeServiceImpl implements PermissionMenuRangeService{

    @Autowired
    PermissionMenuRangeMapper permissionMenuRangeMapper;
    /**
     * 查找所有数据范围权限
    * @author yll
    * @date 2017年4月5日
    * @param PermissionType
    * @param PermissionID
    * @return
    * @throws ServiceBizException
    * (non-Javadoc)
    * @see com.yonyou.dmscloud.manage.service.permission.PermissionMenuRangeService#findMenuRange(Integer, String)
     */
    @Override
    public String[] findMenuRange(Integer permissionType, String permissionid) {
        List<String> permissionids = new ArrayList<>();
        if(!StringUtils.isNullOrEmpty(permissionid)){
            String[] ids = permissionid.split(",");
            for (String splId :ids){
                permissionids.add(splId);
            }
        }
        List<Map<String,Object>> listmap = new ArrayList<>();
        if(StringUtils.isEquals(ManageDictCodeConstants.BILL_TYPE_PERMISSION_ROLE, permissionType.toString())){
            listmap = permissionMenuRangeMapper.findAllListmapOne(permissionids,permissionType,ManageDictCodeConstants.STATUS_IS_YES);
        }else if(StringUtils.isEquals(ManageDictCodeConstants.BILL_TYPE_PERMISSION_POSITION, permissionType.toString())){
            listmap = permissionMenuRangeMapper.findAllListmapTwo(permissionids,permissionType,ManageDictCodeConstants.STATUS_IS_YES);
        }else if(StringUtils.isEquals(ManageDictCodeConstants.BILL_TYPE_PERMISSION_USER, permissionType.toString())){
            listmap = permissionMenuRangeMapper.findAllListmapThree(permissionids,permissionType,ManageDictCodeConstants.STATUS_IS_YES);
        }
        return StringUtil.getTreeMenuSome(listmap, "RANGE_CODE");
    }

}
